package com.twu.biblioteca;

import java.io.IOException;
import java.util.ArrayList;

public class PopulateBooks {

    private ArrayList<PopulateBooks> bookShelf;
    private String title;
    private String author;
    private String category;
    private int bookNum;
    private boolean availability;

    public ArrayList<PopulateBooks> getBookShelf()
    {
        return bookShelf;
    }
    public String getTitle(){
        return title;
    }public boolean isAvailable(){
        return availability ;
    }

    public void addBooksToRepository() {

        this.bookShelf = new ArrayList<PopulateBooks>();
        PopulateBooks book1 = this.insert("Head First Java", "Sierra Bates", "Technical", 323536, true);
        this.bookShelf.add(book1);
        PopulateBooks book2 = this.insert("Digital Fortress", "Dan Brown", "Fiction", 847547, false);
        this.bookShelf.add(book2);
        PopulateBooks book3 = this.insert("My Experiments With Truth", "Mahatma Gandhi", "Non-Fiction", 238973, true);
        this.bookShelf.add(book3);
        PopulateBooks book4 = this.insert("Javascript-The Good Parts", "Douglas Crockford", "Technical", 923536, false);
        this.bookShelf.add(book4);
        PopulateBooks book5 = this.insert("The Effective Executive", "Peter Drucker", "Management", 636536, true);
        this.bookShelf.add(book5);
        PopulateBooks book6 = this.insert("Five Little Pigs", "Agatha Christie", "Fiction", 145656, true);
        this.bookShelf.add(book6);

        this.viewAllBooks();
        this.callReserveBookMethod();

    }
    public PopulateBooks insert(String title, String author, String category, int bookNum, boolean availability) {
        PopulateBooks sample_book = new PopulateBooks();
        sample_book.title=title;
        sample_book.author = author;
        sample_book.category = category;
        sample_book.bookNum = bookNum;
        sample_book.availability = availability;
        return sample_book;
    }
    public void viewAllBooks (){
        for (int index =0;index<(this.bookShelf).size();index++)
        {
            PopulateBooks bookToBeViewed;
            bookToBeViewed = bookShelf.get(index);
            System.out.println(bookToBeViewed.title + " by " +bookToBeViewed.author+" -> category: "+ bookToBeViewed.category);
        }
    }
    public void callReserveBookMethod(){
            BookRelatedQueries callBookRelatedQueries = this.getInstanceOfBookRelatedQueries();
        try {
            callBookRelatedQueries.tellUserIfBookIsReserved();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public BookRelatedQueries getInstanceOfBookRelatedQueries(){
        return new BookRelatedQueries(this);
    }

}